<template>
  <div class="app-container pagebox">
    <div class="bg">
      <a-form v-if="show" layout="inline" :form="form" @submit="handleSubmit" style="padding: 20px 20px">
        <a-form-item>
          <a-select  :getPopupContainer="(triggerNode) => triggerNode.parentNode" style="width: 200px" placeholder="请选择" v-model="equindex" @change="changroup">
            <a-select-option :value="index" v-for="(item, index) in equList" :key="index">
              {{ item.groupname }}
            </a-select-option>
          </a-select>
        </a-form-item>
        <a-form-item>
          <a-select  :getPopupContainer="(triggerNode) => triggerNode.parentNode" style="width: 200px" v-model="MacSNId" placeholder="选择" @change="macSNchange">
            <a-select-option :value="item.macsn" v-for="(item, index) in MacSNs" :key="index">
              {{ item.macnum }}
            </a-select-option>
          </a-select>
        </a-form-item>
      </a-form>
      <div style="">
        <a-table
          :pagination="false"
          :columns="columns"
          :data-source="data"
          :rowKey="
            (record, index) => {
              return index;
            }
          "
        />
      </div>
      <div style="padding: 20px">
        <a-pagination
          size="small"
          :current="pageNum"
          :pageSize="pageSize"
          :total="total"
          :show-total="(total) => `一共 ${total} 条`"
          :default-page-size="10"
          @change="changepageSignIn"
        />
      </div>
    </div>
  </div>
</template>
<script>
//
import api from '@/api/equipment';
const columns = [
  {
    title: '程序名',
    dataIndex: 'produceName',
  },
  {
    title: '加工机床',
    dataIndex: 'macNumb',
  },
  {
    title: '加工开始时间',
    dataIndex: 'startTime',
  },
  {
    title: '加工结束时间',
    dataIndex: 'endTime',
  },
  {
    title: '加工时间',
    dataIndex: 'produceTime',
  },
  {
    title: '主轴运行时长',
    dataIndex: 'spindleTime',
  },
  {
    title: '主轴最大负载',
    dataIndex: 'maxLoad',
  },
  {
    title: '平均修调',
    dataIndex: 'override',
  },
  {
    title: '当前计件数',
    dataIndex: 'partCount',
  },
];

export default {
  data() {
    return {
      data: [],
      columns,
      form: { num: 1 },
      options1: [],
      options2: [],
      CompanyId: null,
      equList: [],
      equID: null,
      equindex: 0,
      MacSNsList: [],
      MacSNId: null,
      username: null,
      MacSNs: [],
      pageSize: 10,
      pageNum: 1,
      total: 0,
      show: true,
    };
  },
  created() {
    if (this.$route.query.macsn) {
      this.MacSNId = this.$route.query.macsn;
      this.equID = this.$route.query.groupid;
      this.show = false;
    }
    let roleId = localStorage.getItem('roleId');
    if (roleId == 1) {
      this.CompanyId = localStorage.getItem('compid');
    } else {
      this.CompanyId = localStorage.getItem('choseCompanyId');
    }
    this.username = this.userName = localStorage.getItem('userName');
    this.getEquGroup();
  },
  methods: {
    changepageSignIn(size) {
      this.pageNum = size;
      this.getAllProduce();
    },
    macSNchange(id) {
      this.pageNum = 1;
      this.MacSNId = id;
      this.getAllProduce();
    },
    changroup(index) {
      this.equID = this.equList[index].groupid;
      if (this.equID == -2) {
        this.MacSNs = [];
        this.MacSNId = null;
      } else {
        this.MacSNs = this.equList[index].MacSNs;
        this.MacSNId = this.MacSNs[0].macsn;
      }
      this.pageNum = 1;
      this.getAllProduce();
    },
    getAllProduce() {
      let params = {
        Username: this.username,
        companyId: this.CompanyId,
        groupId: this.equID,
        macSN: this.MacSNId,
        pageSize: this.pageSize,
        pageNum: this.pageNum,
      };
      api.getAllProduce(params).then((res) => {
        this.data = res.data.rows;
        this.total = res.data.total;
      });
    },
    getEquGroup() {
      let params = {
        Username: this.username,
        compid: this.CompanyId,
      };
      api.CompanyGroupList(params).then((res) => {
        this.equList = res.Data;
        this.equID = this.equList.unshift({ groupname: '全部', groupid: -2 });
        this.equID = this.equList[0].groupid;
        if (this.equList[0].MacSNs) {
          this.MacSNs = this.equList[0].MacSNs;
          this.MacSNId = this.MacSNs[0].macsn;
        }

        this.getAllProduce();
      });
    },
    handleSubmit() {},
  },
};
</script>
<style scoped lang="less">
@import 'index.less';
</style>
